window.onload = function() {
	// 加载
	var oLoad = document.getElementById("load");
	
	oLoad.className = "load-active";
	
	/* 整页滚动 */
	var curIndex = 0;
	var container = $("#container");
	var sumCount = $(".section").length;
	var $window = $(window);
	var oCon = document.getElementById("container");
	var oNavUl = document.getElementsByClassName("nav-ul")[0];
	var aNavUlA = oNavUl.getElementsByTagName("a");
	
	window.onresize = function () {// 浏览器窗口改变重新加载
		move();
	}

	var duration = 500;
	//时间控制
	var aniTime = 0;
	
	for (let i = 0; i < aNavUlA.length; i++) {
		aNavUlA[i].index = i;
	}

	var scrollFunc = function(e) {
		//如果动画还没执行完，则return
		if(new Date().getTime() < aniTime + duration) {
			return;
		}
		e = e || window.event;
		var t = 0;
		if(e.wheelDelta) { //IE/Opera/Chrome
			t = e.wheelDelta;
			if(t > 0 && curIndex > 0) {
				//上滚动
				movePrev();
			} else if(t < 0 && curIndex < sumCount - 1) {
				//下滚动
				moveNext();
			}
		} else if(e.detail) { //Firefox
			t = e.detail;
			if(t < 0 && curIndex > 0) {
				//上滚动
				movePrev();
			} else if(t > 0 && curIndex < sumCount - 1) {
				//下滚动
				moveNext();
			}
		}
	};

	function move() {
		//获取动画开始时的时间
		container.css("transform", "translate3D(0, -" + (curIndex) * $window.height() + "px, 0)");
	}
	
	//下滚动
	function moveNext() {
		oCon.style.transitionDuration = "500ms";
		
		//获取动画开始时的时间
		aniTime = new Date().getTime();
		
		container.css("transform", "translate3D(0, -" + (++curIndex) * $window.height() + "px, 0)");
		
		rollingStyle();
		
		setTimeout(function() {
			oCon.style.transitionDuration = "0ms";
		}, 500);

		if(curIndex == 0){
			About(removeClass);
			GamePosters(removeClass);
			mySwiper1.autoplay.stop();
			GameInfo(removeClass);
			CarrierCooperation(removeClass);
		}else if(curIndex == 1) {
			About(addClass);
			GamePosters(removeClass);
			mySwiper1.autoplay.start();
			GameInfo(removeClass);
			CarrierCooperation(removeClass);
		}else if (curIndex == 2) {
			GamePosters(addClass);
			About(removeClass);
			mySwiper1.autoplay.stop();
			GameInfo(removeClass);
			CarrierCooperation(removeClass);
		}else if (curIndex == 3) {
			GameInfo(addClass);
			About(removeClass);
			GamePosters(removeClass);
			mySwiper1.autoplay.stop();
			CarrierCooperation(removeClass);
		}else if (curIndex == 4) {
			CarrierCooperation(addClass);
			GameInfo(removeClass);
			About(removeClass);
			GamePosters(removeClass);
			mySwiper1.autoplay.stop();
		}
	}
	
	//上滚动
	function movePrev() {
		oCon.style.transitionDuration = "500ms";
		
		//获取动画开始时的时间
		aniTime = new Date().getTime();
		
		container.css("transform", "translate3D(0, -" + (--curIndex) * $window.height() + "px, 0)");
		
		rollingStyle();
		
		setTimeout(function() {
			oCon.style.transitionDuration = "0ms";
		}, 500);

		if(curIndex == 0){
			About(removeClass);
			GamePosters(removeClass);
			mySwiper1.autoplay.stop();
			GameInfo(removeClass);
			CarrierCooperation(removeClass);
		}else if(curIndex == 1) {
			About(addClass);
			GamePosters(removeClass);
			mySwiper1.autoplay.start();
			GameInfo(removeClass);
			CarrierCooperation(removeClass);
		}else if (curIndex == 2) {
			GamePosters(addClass);
			About(removeClass);
			mySwiper1.autoplay.stop();
			GameInfo(removeClass);
			CarrierCooperation(removeClass);
		}else if (curIndex == 3) {
			GameInfo(addClass);
			About(removeClass);
			GamePosters(removeClass);
			mySwiper1.autoplay.stop();
			CarrierCooperation(removeClass);
		}else if (curIndex == 4) {
			CarrierCooperation(addClass);
			GameInfo(removeClass);
			About(removeClass);
			GamePosters(removeClass);
			mySwiper1.autoplay.stop();
		}
	}
	
	//导航栏点击
	function moveClick() {
		for (let i = 0; i < aNavUlA.length; i++) {
			aNavUlA[i].index = i;
			
			aNavUlA[i].onclick = function () {
				oCon.style.transitionDuration = "500ms";
				
				//获取动画开始时的时间
				aniTime = new Date().getTime();
				
				curIndex = this.index;
				
				container.css("transform", "translate3D(0, -" + (curIndex) * $window.height() + "px, 0)");
				
				rollingStyle();
		
				setTimeout(function() {
					oCon.style.transitionDuration = "0ms";
				}, 500);
				if(curIndex == 0){
					About(removeClass);
					GamePosters(removeClass);
					mySwiper1.autoplay.stop();
					GameInfo(removeClass);
					CarrierCooperation(removeClass);
				}else if(curIndex == 1) {
					About(addClass);
					GamePosters(removeClass);
					mySwiper1.autoplay.start();
					GameInfo(removeClass);
					CarrierCooperation(removeClass);
				}else if (curIndex == 2) {
					GamePosters(addClass);
					About(removeClass);
					mySwiper1.autoplay.stop();
					GameInfo(removeClass);
					CarrierCooperation(removeClass);
				}else if (curIndex == 3) {
					GameInfo(addClass);
					About(removeClass);
					GamePosters(removeClass);
					mySwiper1.autoplay.stop();
					CarrierCooperation(removeClass);
				}else if (curIndex == 4) {
					CarrierCooperation(addClass);
					GameInfo(removeClass);
					About(removeClass);
					GamePosters(removeClass);
					mySwiper1.autoplay.stop();
				}
			}
		}
	}
	moveClick();
	
	// 导航栏样式
	function rollingStyle() {
		setTimeout(function () {
			for (var i = 0; i < oNavUl.children[0].children.length; i++) {
				oNavUl.children[0].children[i].children[0].children[0].className = "";
			}
			
			oNavUl.children[0].children[curIndex].children[0].children[0].className = "nav-active";
		}, 500);
	}

	function init() {
		/*注册事件*/
		if(document.addEventListener) {
			document.addEventListener("DOMMouseScroll", scrollFunc, false);
		}
		//W3C
		window.onmousewheel = document.onmousewheel = scrollFunc; //IE/Opera/Chrome
	}

	init();
	
	
	// 轮播
	var oHome = document.getElementById("home");
	var aHomeDiv = oHome.children;
	var oHomePaging = document.getElementsByClassName("home-paging")[0];
	var aHomePagingSpan = oHomePaging.getElementsByTagName("span");
	var aHomeContainer = document.getElementsByClassName("home-container");
	
	// 轮播变量
	var clientWidth = document.documentElement.clientWidth || document.body.clientWidth;
	oHome.style.left = -clientWidth + "px";
	for(var i = 0; i < aHomeDiv.length; i++) {
		aHomeDiv[i].style.width = clientWidth + "px";
	}

	var Carousel = 0;
	var speedHome = 2;
	var speedPagin = 1;
	
	// 分页样式
	function PagingActive() {
		for (var i = 0; i < aHomePagingSpan.length; i++) {
			aHomePagingSpan[i].className = "";
		}
		aHomePagingSpan[speedPagin].className = "home-paging-active";
	}
	
	// 浏览器加载完成执行第一个动画
	home1active(addClass);
	
	// 轮播器
	function HomeCarousel() {
		
		var hometimer = null;
		
		// 分页器
		for (var i = 0; i < aHomePagingSpan.length; i++) {
			aHomePagingSpan[i].index = i;
			aHomePagingSpan[i].onclick = function () {
				if (this.index == Carousel) return;
				
				if(speedHome == 2) { oHome.style.left = -clientWidth + "px"; }
				
				speedHome = 3;
				
				Carousel = this.index;
				
				homeactive();
				
				speedPagin = this.index;
				
				PagingActive();
				
				startMove(oHome, {left: (this.index + 1) * -clientWidth});
				
				clearInterval(hometimer);
				
				eval("home" + (speedPagin + 1) + "active" + "(addClass);");
			}
		}
		
		clearInterval(hometimer);
		
		var hometimer = setInterval (function () {
			if(curIndex != 0) return;
			
			homeactive();
			
			PagingActive();
			
			if(speedHome == 2) { oHome.style.left = -clientWidth + "px"; }
			
			startMove(oHome, {left: speedHome * -clientWidth});
			
			var findex = speedHome == 4 ? 1 : speedHome;
			eval("home" + findex + "active" + "(addClass);");
			
			if(speedHome == aHomeDiv.length - 1) {
				speedHome = 1;
			}
			
			if(speedPagin == aHomePagingSpan.length - 1) {
				speedPagin = -1;
			}
			
			if(Carousel == 2) {
				Carousel = -1;
			}
			
			speedHome++;
			speedPagin++;
			Carousel++;
		}, 5000);
	}
	HomeCarousel();
	
	function home1active(fName) {
		// home - 轮播1 - 动画
		var aHomeTxtLeft = document.getElementsByClassName("home-txt-left");
		var aHomeTxtLeftP0 = aHomeTxtLeft[0].getElementsByTagName("p");
		var aHomeTxtLeftP1 = aHomeTxtLeft[1].getElementsByTagName("p");
		var aHomeTxtLeftRightDiv0 = document.getElementsByClassName("home-txt-right")[0];
		var aHomeTxtLeftRightDiv1 = document.getElementsByClassName("home-txt-right")[1];
		
		for (let i = 0; i < aHomeTxtLeftP0.length; i++) {
			fName(aHomeTxtLeftP0[i], "home-txt-left-active-p" +  (i + 1));
			fName(aHomeTxtLeftP1[i], "home-txt-left-active-p" +  (i + 1));
		}
		
		fName(aHomeTxtLeftRightDiv0, "home-txt-right-active");
		fName(aHomeTxtLeftRightDiv1, "home-txt-right-active");
	}
	
	function home2active(fName) {
		// home - 轮播2 - 动画
		var oHomeTxtCentenr = document.getElementsByClassName("home-txt-center")[0];
		var aHomeTxtCentenrP = oHomeTxtCentenr.getElementsByTagName("p");
		var oHomeTxtI = document.getElementsByClassName("home-txt-i")[0];
		var oHomeTxtCentenrUl = oHomeTxtCentenr.getElementsByTagName("ul")[0];
		
		fName(aHomeTxtCentenrP[0], "home-txt-centenr-active-p1");
		
		fName(oHomeTxtI, "home-txt-home-txt-i-active-p");
		
		fName(oHomeTxtCentenrUl, "home-txt-centenr-active-li");
	}
	
	function home3active(fName) {
		// home - 轮播3 - 动画
		var oHome3Left = document.getElementsByClassName("home-3-left")[1];
		var oHome3Right = document.getElementsByClassName("home-3-right")[1];
		var oHome3RightP = oHome3Right.getElementsByTagName("p")[0];
		
		fName(oHome3Left, "home-3-left-active");
		
		fName(oHome3RightP, "home-3-right-active-span");
	}
	
	function homeactive() {
		home1active(removeClass);
		home2active(removeClass);
		home3active(removeClass);
	}

	// 下一页点击
	var oWindowNext = document.getElementById("window-next");
	oWindowNext.onclick = function () {
		if(curIndex == 5) return;
		oCon.style.transitionDuration = "500ms";
		
		//获取动画开始时的时间
		aniTime = new Date().getTime();
		
		container.css("transform", "translate3D(0, -" + (++curIndex) * $window.height() + "px, 0)");
		
		rollingStyle();
		
		setTimeout(function() {
			oCon.style.transitionDuration = "0ms";
		}, 500);
		
		if(curIndex == 1) {
			About(addClass);
			GamePosters(removeClass);
			mySwiper1.autoplay.start();
			GameInfo(removeClass);
			CarrierCooperation(removeClass);
		}else if (curIndex == 2) {
			GamePosters(addClass);
			About(removeClass);
			mySwiper1.autoplay.stop();
			GameInfo(removeClass);
			CarrierCooperation(removeClass);
		}else if (curIndex == 3) {
			GameInfo(addClass);
			About(removeClass);
			GamePosters(removeClass);
			mySwiper1.autoplay.stop();
			CarrierCooperation(removeClass);
		}else if (curIndex == 4) {
			CarrierCooperation(addClass);
			GameInfo(removeClass);
			About(removeClass);
			GamePosters(removeClass);
			mySwiper1.autoplay.stop();
		}
	}
	
	//About轮播
	var mySwiper1 = new Swiper ('#swiper1', {
	    loop: true,//循环轮播模式选项，默认false关闭，true开启。
	    
	    //轮播
	    autoplay: false,
	});
	
	/* About动画 */
	function About(fName) {
		var oAboutL = document.getElementsByClassName("about-left")[0];
		var oAboutLH3 = oAboutL.getElementsByTagName("h3")[0];
		var oAboutLH3Font = oAboutLH3.getElementsByTagName("font")[0];
		var oAboutLH3Span = oAboutLH3.getElementsByTagName("span")[0];
		var oAboutLUl = oAboutL.getElementsByTagName("ul")[0];
		var aAboutLUlLi = oAboutLUl.getElementsByTagName("li");
		var aAboutLP = oAboutL.getElementsByTagName("p")[0];
		var aAboutLA = oAboutL.getElementsByTagName("a")[0];
		
		fName(oAboutLH3Font, "about-left-font-active");
		fName(oAboutLH3Span, "about-left-span-active");
		for (var i = 0; i < aAboutLUlLi.length; i++) {
			fName(aAboutLUlLi[i], "about-left-li-active");
		}
		fName(aAboutLP, "about-left-p-active");
		fName(aAboutLA, "about-left-a-active");
		
		var oN3 = document.getElementsByClassName("n3")[0];
		var aN1 = document.getElementsByClassName("n1");
		var aN0 = document.getElementsByClassName("n0");
		var aN0_1 = document.getElementsByClassName("n0-1");
		for (var i = 0; i < aN1.length; i++) {
			fName(aN1[i], "about-n1-active");
		}
		fName(oN3, "about-n3-active");
		for (var i = 0; i < aN0.length; i++) {
			fName(aN0[i], "about-n0-active");
		}
		for (var i = 0; i < aN0_1.length; i++) {
			fName(aN0_1[i], "about-n0-active-1");
		}
		
		var oAboutR = document.getElementsByClassName("about-right")[0];
		var oAboutRSwiperC = oAboutR.getElementsByClassName("swiper-container")[0];
		fName(oAboutR, "about-right-active");
		fName(oAboutRSwiperC, "swiper-container-acative");
	}
	
	//Game Posters cs3动画
	function GamePosters(fName) {
		var oGame = document.getElementById("game");
		var oGameContainer = oGame.getElementsByClassName("game-container")[0];
		var oGameLeft = oGame.getElementsByClassName("game-left")[0];
		var oGameLeftH3 = oGameLeft.getElementsByTagName("h3")[0];
		var oGameLeftP = oGameLeft.getElementsByTagName("p")[0];
		var oGameLeftA = oGameLeft.getElementsByTagName("a")[0];
		var oGameCarousel = document.querySelector(".game-carousel");
		
		fName(oGameContainer, "game-container-active");
		fName(oGameLeftH3, "game-left-h3-active");
		fName(oGameLeftP, "game-left-p-active");
		fName(oGameLeftA, "about-left-a-active");
		fName(oGameCarousel, "game-carousel-active");
	}

	var oGameBtnLeft = document.querySelector(".game-btn-left");
	var oGameBtnRight = document.querySelector(".game-btn-right");
	var oGameCarousel = document.querySelector(".game-carousel");
	var aGameCarouselUl = oGameCarousel.getElementsByTagName("ul");
	var oGameCarouselUlLi0 = aGameCarouselUl[0].getElementsByTagName("li")[0];
	var oGameCarouselUlLi2 = aGameCarouselUl[0].getElementsByTagName("li")[2];
	
	oGameBtnLeft.onclick = function () {
		for (var i = 0; i < aGameCarouselUl.length; i++) {
			var l = parseInt(aGameCarouselUl[i].style.left) ? parseInt(aGameCarouselUl[i].style.left) : 0;
			if(l == 293 || l == -293) {
				if(i == 0) {
					startMove(oGameCarouselUlLi2, {opacity: 0});
					startMove(oGameCarouselUlLi0, {opacity: 100});
				}
				startMove(aGameCarouselUl[i], {left: l + 293});
			}
		}
	}
	oGameBtnRight.onclick = function () {
		for (var i = 0; i < aGameCarouselUl.length; i++) {
			var l = parseInt(aGameCarouselUl[i].style.left) ? parseInt(aGameCarouselUl[i].style.left) : 0;
			if(l == 586 || l == 0) {
				if(i == 0) {
					startMove(oGameCarouselUlLi0, {opacity: 0});
					startMove(oGameCarouselUlLi2, {opacity: 100});
				}
				startMove(aGameCarouselUl[i], {left: l - 293});
			}
		}
	}

	//Game Info
	//Game Info轮播
	var mySwiper2 = new Swiper ('#swiper2', {
		direction : "vertical",
		// mousewheel: true,
	    
	    //轮播
	    autoplay: false,
	});

	function GameInfo(fName) {
		var oInfoImg = document.querySelector(".info-img");
		var oInfoText = document.querySelector(".info-text");
		var oInfoRight = document.querySelector(".info-right");

		fName(oInfoImg, "info-img-active");
		fName(oInfoText, "info-text-active");
		fName(oInfoRight, "info-right-active");
	}

	//Carrier Cooperation
	//Carrier Cooperation轮播
	var mySwiper3 = new Swiper("#swiper3", {
		slidesPerView: 4,
		slidesPerColumn: 2,
		spaceBetween: 10,
		grabCursor: true,
		navigation: {
		  nextEl: '.carrier-btn-right',
		  prevEl: '.carrier-btn-left',
		},
	});

	function CarrierCooperation(fName) {
		var oCarrierContainer = document.querySelector(".carrier-container");

		fName(oCarrierContainer, "carrier-container-active");
	}
	var map = new BMap.Map("allmap");
	var point = new BMap.Point(116.404, 39.915);
	map.centerAndZoom(point, 15);
	var marker = new BMap.Marker(point);  // 创建标注
	map.addOverlay(marker);               // 将标注添加到地图中
	marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
}